package com.fengmi.controller;

import com.fengmi.dto.PageDTO;
import com.fengmi.entity.MallGoodsTemplate;
import com.fengmi.service.GoodsTemplateService;
import com.fengmi.vo.PageResultVO;
import com.fengmi.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 123
 * @Date 2022/1/25 10:00
 * @Version 1.0
 */

@RestController
@RequestMapping("template")
@CrossOrigin
@Api(tags = "商品模板管理")
public class GoodsTemplateController {

    @Autowired
    private GoodsTemplateService templateService;

    @PostMapping("save")
    @ApiOperation("模板添加")
    public ResultVO saveTemplate(@RequestBody @ApiParam("模板添加实例对象") MallGoodsTemplate mallGoodsTemplate) {
        return templateService.saveGoodsTemplate(mallGoodsTemplate);
    }

    @PostMapping("page")
    @ApiOperation("分页条件查询模板信息")
    public PageResultVO<MallGoodsTemplate> findPage(@RequestBody @ApiParam("查询条件组合实体类") PageDTO<MallGoodsTemplate> pageDTO) {
        return templateService.selectTemByPage(pageDTO);
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除模板")
    public ResultVO deleteTemplate(@PathVariable String id) {
        return templateService.delOneById(id);
    }

    @GetMapping("{id}")
    public ResultVO findOne(@PathVariable String id) {
        return templateService.selectOneById(id);
    }

    @GetMapping
    public ResultVO findAll() {
        return templateService.selectAllTemp();
    }

    @PutMapping("update")
    public ResultVO updateTemplate(@RequestBody MallGoodsTemplate mallGoodsTemplate) {
        return templateService.updateTemp(mallGoodsTemplate);
    }
}
